#ifdef VERTEX
uniform mat4 uProjMatrix;
uniform mat4 uViewMatrix;
uniform mat4 uModelMatrix;
uniform vec4 uBaseColor;

layout(location = 0) in vec4 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(location = 2) in vec4 aNormal;
layout(location = 3) in vec4 aColor;

out vec2 vTexCoord;
out vec4 vColor;
out vec3 vViewDir;

void main()
{
	vec4 position = uViewMatrix * uModelMatrix * aPosition;

	vTexCoord = aTexCoord;
	vColor = aColor * uBaseColor;
	vViewDir = position.xyz;

	gl_Position = uProjMatrix * position;
}
#endif

#ifdef FRAGMENT
uniform sampler2D uTexture;
uniform vec3 uEmissiveColor;

in vec2 vTexCoord;
in vec4 vColor;
in vec3 vViewDir;
out vec4 fragColor;

void main()
{
	vec4 color = texture(uTexture, vTexCoord) * vColor;

#ifndef DISABLE_ALPHATEST
	if (color.a < 0.01) discard;
#endif
	color.rgb += uEmissiveColor;

#ifdef ENABLE_TONEMAPPING
	color = common_tonemapping(color);
#endif

#ifdef ENABLE_FOG
	color = common_fog(color, vViewDir);
#endif
	fragColor = color;
}
#endif